import { createRouter, createWebHistory } from "vue-router"
import Home from '../views/Home.vue'
import store from '../store/index'

const routes = [
    {
        path: '/',
        name: 'Home',
        component: Home
    }, {
        path: '/ListView',
        name: 'ListView',
        component: () => import('../views/ListView.vue')
    }, {
        path: '/Login',
        name: 'Login',
        beforeEnter: (to, from, next) => {
            console.log(store.state.user)
            if (store.state.user.isLogin) {
                next()
            } else {
                next('Login')
            }
        },
        component: () => import('../views/Login.vue')
    }, {
        path: '/Me',
        name: 'Me',
        component: () => import('../views/Me.vue')
    }, {
        path: '/Search',
        name: 'Search',
        component: () => import('../views/SearchMusic.vue')
    }, {
        path: '/PlayMusic',
        name: 'PlayMusic',
        component: () => import('../views/PlayMusic.vue')
    }
]

const router = createRouter({
    // history: createWebHistory(process.env.BASW_URL),
    history: createWebHistory(),
    routes
})

export default router